<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_app_func('global','dianping');//导入程序处理函数
class bbs extends admin {
	function __construct() {
		parent::__construct();
		//实例化BBS数据模型
		$this->bbs = pc_base::load_model('bbs_model');
		$this->module = pc_base::load_model('module_model');
		pc_base::load_sys_class('form');
  	}
 	
	public function init() {
		$where = array();
		$search = array();
		if(isset($_GET['search'])){
			$search = $_GET['search'];
			if(!empty($search['email']))$where[]= "`email`='{$search['email']}'";
			if(!empty($search['keywords']))$where[]= "`title` like '%{$search['keywords']}%'";
			if(!empty($search['start_time']))$where[]= "`datetime` >='{$search['start_time']}'";
			if(!empty($search['end_time']))$where[]= "`datetime` <='{$search['end_time']}'";
			$where = join(' and ', $where );
		}
		
		
		
		//模块数组
//		$module_arr = array();
//		$modules = getcache('modules','commons');
// 		foreach($modules as $module=>$m) $module_arr[$m['module']] = $m['name'];
 		
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$infos = $this->bbs->listinfo($where,$order = 'id DESC',$page, $pages = '4');
		$pages = $this->bbs->pages; 
 		include $this->admin_tpl('list');
 	}
 	
	//批量删除
 	public function delete(){
 		if(!isset($_POST['id']))showmessage('删除失败！！！');
		$ids = $_POST['id'];
		$arr = array();
		
		foreach ($ids as $id){
			$rs = $this->bbs->select(array('pid'=>$id));
			if(!empty($rs)){
				foreach($rs as $row){
					$arr[] = $row['id'];
				}
			}
		}
 		$ids = array_merge($ids, $arr);
 		
 		$this->bbs->delete('`id` in (' . join(',', $ids) . ')');
 		showmessage('批量删除帖子成功！');
 	}

} 	
 	
?>